package yu.liu.personal.app.myapplication.components.items;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import yu.liu.personal.app.myapplication.R;
import yu.liu.personal.app.myapplication.components.ViewCollection;
import yu.liu.personal.app.myapplication.components.views.CalculatorPanelPopupWindow;
import yu.liu.personal.app.myapplication.models.AVGItem;

/**
 * Created by Administrator on 2016/9/25.
 */

public class AVGListChildItem extends ViewCollection {

    @BindView(R.id.tvHPChildItem)
    TextView tvHPChildItem;

    @BindView(R.id.tvArmorChildItem)
    TextView tvArmorChildItem;

    @BindView(R.id.tvShieldChildItem)
    TextView tvShieldChildItem;

    @BindView(R.id.tvResistChildItem)
    TextView tvResistChildItem;

    @BindView(R.id.tvOilChildItem)
    TextView tvOilChildItem;

    @BindView(R.id.tvAmmoChildItem)
    TextView tvAmmoChildItem;

    @BindView(R.id.tvScoutChildItem)
    TextView tvScoutChildItem;

    @BindView(R.id.tvAttackChildItem)
    TextView tvAttackChildItem;

    @BindView(R.id.tvSpeedChildItem)
    TextView tvSpeedChildItem;

    @BindView(R.id.tvSkillChildItem)
    TextView tvSkillChildItem;

    @BindView(R.id.tvEquipChildItem)
    TextView tvEquipChildItem;

    @BindView(R.id.btnCalChildItem)
    View btnCalChildItem;

    private AVGItem item;
    private CalculatorPanelPopupWindow calPopwin;


    public AVGListChildItem(Context context) {
        super(context);
    }

    public void setItem(AVGItem item) {
        this.item = item;
    }

    @Override
    protected void loadViews() {
//        tvHPChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvHPChildItem"));
//        tvArmorChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvArmorChildItem"));
//        tvShieldChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvShieldChildItem"));
//        tvResistChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvResistChildItem"));
//        tvOilChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvOilChildItem"));
//        tvAmmoChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvAmmoChildItem"));
//        tvScoutChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvScoutChildItem"));
//        tvAttackChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvAttackChildItem"));
//        tvSpeedChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvSpeedChildItem"));
//        tvSkillChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvSkillChildItem"));
//        tvEquipChildItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvEquipChildItem"));
        ButterKnife.bind(this, contentView);
    }

    @Override
    public void updateViews() {
        if(item != null) {
            tvHPChildItem.setText("耐久:"+String.valueOf(item.hp));
            tvArmorChildItem.setText("装甲:"+String.valueOf(item.armor));
            tvShieldChildItem.setText("护盾:"+String.valueOf(item.shield));
            tvResistChildItem.setText("抵抗:"+String.valueOf(item.resist));
            tvOilChildItem.setText("油耗:"+String.valueOf(item.oilConsume));
            tvAmmoChildItem.setText("弹耗:"+String.valueOf(item.ammoConsume));
            tvScoutChildItem.setText("侦察:"+String.valueOf(item.scout));
            tvAttackChildItem.setText("火力:"+String.valueOf(item.atk));
            tvSpeedChildItem.setText("机动:"+String.valueOf(item.spd));
            tvSkillChildItem.setText("技能:"+item.mainSkill+","+item.subSkill);
            StringBuffer buffer = new StringBuffer();
            if(item.equipDetail != null) {
                for (AVGItem.MapEntity entity : item.equipDetail) {
                    buffer.append(entity.Key);
                    buffer.append(" X ");
                    buffer.append(entity.Value);
                    buffer.append("\t");
                }
                buffer.deleteCharAt(buffer.length() - 1);
            }
            tvEquipChildItem.setText("装备:"+buffer.toString());
        }
    }

    @OnClick(R.id.btnCalChildItem)
    public void CalculateClick() {
        calPopwin = new CalculatorPanelPopupWindow(resContext);
        calPopwin.initWindow(contentView, resManager.getResourceID("layout",
                "layout_popwin_avg_list_child_item_cal"));
        calPopwin.setFocusable(true);
        calPopwin.setItem(item);
        calPopwin.showPopupWindow();
        calPopwin.updateViews();
    }
}
